/*
 * @Author: your name
 * @Date: 2022-03-28 16:17:03
 * @LastEditTime: 2022-07-31 20:18:44
 * @LastEditors: YNT 2501512800@qq.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \22-03-19 智慧社区\pages\callPhone\index.js
 */
import SpecialModel from '../../api/special'
import { getStorage } from '../../utils/storageSyncTool'
import Toast from '@vant/weapp/toast/toast'
import Dialog from '@vant/weapp/dialog/dialog'

Page({
  data: {
    nvabarData: {
      navigationBarTextStyle: 'black', // 胶囊主题 white || black
      navigationBarBackground: '#FEFEFE', // 导航栏背景色
      navigationBarTitleText: '一键管家',
    },
  },
  onLoad: function () {
    wx.showLoading()
    let _that = this
    let status = getStorage('status')
    _that.setData({
      userStatus: status,
    })
    SpecialModel.getAdminPhone()
      .then(({ data }) => {
        let phone = data.phone
        let name = data.sub_admin_name
        _that.setData({
          phone,
          name,
        })
      })
      .catch((err) => [])
      .finally(() => {
        wx.hideLoading()
      })
  },
  tel: function () {
    let that = this
    let userStatus = that.data.userStatus
    if (userStatus == 1) {
      return Toast('等待管理员完成实名审核')
    } else if (userStatus == 0 || userStatus == 3) {
      return Dialog.confirm({
        title: '提示',
        message: '请先完善实名信息',
        confirmButtonText: '页面跳转',
      })
        .then(() => {
          wx.navigateTo({
            url: '/subPackages/otherPackages/pages/realnameregistration/index',
          })
        })
        .catch(() => {})
    }
    let phone = that.data.phone
    if (phone) {
      wx.makePhoneCall({
        phoneNumber: `${phone}`,
        success: function () {},
        fail: function () {},
      })
    } else {
      Toast('小区暂无管家！')
    }
  },
})
